<!DOCTYPE html><html lang="zh-CN" data-theme="dark"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width,initial-scale=1"><title>Vue源码开发-组件的渲染10 | 北城韩雨</title><meta name="keywords" content="Vue"><meta name="author" content="北城韩雨"><meta name="copyright" content="北城韩雨"><meta name="format-detection" content="telephone=no"><meta name="theme-color" content="#0d0d0d"><meta name="description" content="Vue">
<meta property="og:type" content="article">
<meta property="og:title" content="Vue源码开发-组件的渲染10">
<meta property="og:url" content="http://example.com/2021/01/08/Vue%E6%BA%90%E7%A0%81%E5%BC%80%E5%8F%91%E4%B9%8B%E7%BB%84%E4%BB%B6%E7%9A%84%E6%B8%B2%E6%9F%9310/index.html">
<meta property="og:site_name" content="北城韩雨">
<meta property="og:description" content="Vue">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fpic.vjshi.com%2F2018-07-17%2F3eca5394963b50e37b7be2ba320029ec%2F00003.jpg%3Fx-oss-process%3Dstyle%2Fwatermark&refer=http%3A%2F%2Fpic.vjshi.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1629530644&t=10679b5732c52e39eeb588040240a790">
<meta property="article:published_time" content="2021-01-07T16:00:00.000Z">
<meta property="article:modified_time" content="2021-01-07T16:00:00.000Z">
<meta property="article:author" content="北城韩雨">
<meta property="article:tag" content="Vue">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fpic.vjshi.com%2F2018-07-17%2F3eca5394963b50e37b7be2ba320029ec%2F00003.jpg%3Fx-oss-process%3Dstyle%2Fwatermark&refer=http%3A%2F%2Fpic.vjshi.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1629530644&t=10679b5732c52e39eeb588040240a790"><link rel="shortcut icon" href="/img/favicon.png"><link rel="canonical" href="http://example.com/2021/01/08/Vue%E6%BA%90%E7%A0%81%E5%BC%80%E5%8F%91%E4%B9%8B%E7%BB%84%E4%BB%B6%E7%9A%84%E6%B8%B2%E6%9F%9310/"><link rel="preconnect" href="//cdn.jsdelivr.net"/><link rel="preconnect" href="//busuanzi.ibruce.info"/><link rel="stylesheet" href="/css/index.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free/css/all.min.css" media="print" onload="this.media='all'"><script>const GLOBAL_CONFIG = { 
  root: '/',
  algolia: undefined,
  localSearch: undefined,
  translate: undefined,
  noticeOutdate: undefined,
  highlight: {"plugin":"highlighjs","highlightCopy":true,"highlightLang":true,"highlightHeightLimit":false},
  copy: {
    success: '复制成功',
    error: '复制错误',
    noSupport: '浏览器不支持'
  },
  relativeDate: {
    homepage: false,
    post: false
  },
  runtime: '',
  date_suffix: {
    just: '刚刚',
    min: '分钟前',
    hour: '小时前',
    day: '天前',
    month: '个月前'
  },
  copyright: undefined,
  lightbox: 'mediumZoom',
  Snackbar: undefined,
  source: {
    jQuery: 'https://cdn.jsdelivr.net/npm/jquery@latest/dist/jquery.min.js',
    justifiedGallery: {
      js: 'https://cdn.jsdelivr.net/npm/justifiedGallery/dist/js/jquery.justifiedGallery.min.js',
      css: 'https://cdn.jsdelivr.net/npm/justifiedGallery/dist/css/justifiedGallery.min.css'
    },
    fancybox: {
      js: 'https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@latest/dist/jquery.fancybox.min.js',
      css: 'https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@latest/dist/jquery.fancybox.min.css'
    }
  },
  isPhotoFigcaption: false,
  islazyload: false,
  isanchor: false
}</script><script id="config-diff">var GLOBAL_CONFIG_SITE = {
  title: 'Vue源码开发-组件的渲染10',
  isPost: true,
  isHome: false,
  isHighlightShrink: false,
  isToc: true,
  postUpdate: '2021-01-08 00:00:00'
}</script><noscript><style type="text/css">
  #nav {
    opacity: 1
  }
  .justified-gallery img {
    opacity: 1
  }

  #recent-posts time,
  #post-meta time {
    display: inline !important
  }
</style></noscript><script>(win=>{
    win.saveToLocal = {
      set: function setWithExpiry(key, value, ttl) {
        if (ttl === 0) return
        const now = new Date()
        const expiryDay = ttl * 86400000
        const item = {
          value: value,
          expiry: now.getTime() + expiryDay,
        }
        localStorage.setItem(key, JSON.stringify(item))
      },

      get: function getWithExpiry(key) {
        const itemStr = localStorage.getItem(key)

        if (!itemStr) {
          return undefined
        }
        const item = JSON.parse(itemStr)
        const now = new Date()

        if (now.getTime() > item.expiry) {
          localStorage.removeItem(key)
          return undefined
        }
        return item.value
      }
    }
  
    win.getScript = url => new Promise((resolve, reject) => {
      const script = document.createElement('script')
      script.src = url
      script.async = true
      script.onerror = reject
      script.onload = script.onreadystatechange = function() {
        const loadState = this.readyState
        if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
        script.onload = script.onreadystatechange = null
        resolve()
      }
      document.head.appendChild(script)
    })
  
      win.activateDarkMode = function () {
        document.documentElement.setAttribute('data-theme', 'dark')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#0d0d0d')
        }
      }
      win.activateLightMode = function () {
        document.documentElement.setAttribute('data-theme', 'light')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#ffffff')
        }
      }
      const t = saveToLocal.get('theme')
    
          if (t === 'dark') activateDarkMode()
          else if (t === 'light') activateLightMode()
        
    const detectApple = () => {
      if (GLOBAL_CONFIG_SITE.isHome && /iPad|iPhone|iPod|Macintosh/.test(navigator.userAgent)){
        document.documentElement.classList.add('apple')
      }
    }
    detectApple()
    })(window)</script><link rel="stylesheet" href="/css/custom.css"  media="defer" onload="this.media='all'"><link rel="stylesheet" href="/css/coin.css"  media="defer" onload="this.media='all'"><link rel="stylesheet" href="/css/liuxing.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/l-lin/font-awesome-animation/dist/font-awesome-animation.min.css"  media="defer" onload="this.media='all'"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/swiper/swiper-bundle.min.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/zhheo/JS-Heo@main/bb/showbb_in_index.css"><!-- hexo injector head_end start --><link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/animate.css/4.1.1/animate.min.css" media="print" onload="this.media='screen'"><link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/l-lin/font-awesome-animation/dist/font-awesome-animation.min.css" media="defer" onload="this.media='all'"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/hexo-butterfly-tag-plugins-plus/lib/tag_plugins.min.css" media="defer" onload="this.media='all'"><!-- hexo injector head_end end --><meta name="generator" content="Hexo 5.3.0"></head><body><div id="web_bg"></div><div id="sidebar"><div id="menu-mask"></div><div id="sidebar-menus"><div class="avatar-img is-center"><img src="/img/my.jpg" onerror="onerror=null;src='/img/friend_404.gif'" alt="avatar"/></div><div class="site-data"><div class="data-item is-center"><div class="data-item-link"><a href="/archives/"><div class="headline">文章</div><div class="length-num">65</div></a></div></div><div class="data-item is-center"><div class="data-item-link"><a href="/tags/"><div class="headline">标签</div><div class="length-num">23</div></a></div></div><div class="data-item is-center"><div class="data-item-link"><a href="/categories/"><div class="headline">分类</div><div class="length-num">21</div></a></div></div></div><hr/><div class="menus_items"><div class="menus_item"><a class="site-page faa-parent animated-hover" href="/"><i class="fa-fw fas fa-home faa-tada"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page faa-parent animated-hover" href="/shuoshuo/"><i class="fa-fw fas fa-archive faa-tada"></i><span> 叨逼叨</span></a></div><div class="menus_item"><a class="site-page faa-parent animated-hover" href="/tags/"><i class="fa-fw fas fa-tags faa-tada"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page faa-parent animated-hover" href="/categories/"><i class="fa-fw fas fa-folder-open faa-tada"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page faa-parent animated-hover" href="/link/"><i class="fa-fw fas fa-link faa-tada"></i><span> 友链</span></a></div><div class="menus_item"><a class="site-page faa-parent animated-hover" href="/comments/"><svg class="icon faa-tada" aria-hidden="true"><use xlink:href="#icon-message"></use></svg><span> 留言板</span></a></div><div class="menus_item"><a class="site-page faa-parent animated-hover" href="/about/"><i class="fa-fw fas fa-heart faa-tada"></i><span> 个人简介</span></a></div></div></div></div><div class="post" id="body-wrap"><header class="post-bg" id="page-header" style="background-image: url('https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fpic.vjshi.com%2F2018-07-17%2F3eca5394963b50e37b7be2ba320029ec%2F00003.jpg%3Fx-oss-process%3Dstyle%2Fwatermark&amp;refer=http%3A%2F%2Fpic.vjshi.com&amp;app=2002&amp;size=f9999,10000&amp;q=a80&amp;n=0&amp;g=0n&amp;fmt=jpeg?sec=1629530644&amp;t=10679b5732c52e39eeb588040240a790')"><nav id="nav"><span id="blog_name"><a id="site-name" href="/">北城韩雨</a></span><div id="menus"><div class="menus_items"><div class="menus_item"><a class="site-page faa-parent animated-hover" href="/"><i class="fa-fw fas fa-home faa-tada"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page faa-parent animated-hover" href="/shuoshuo/"><i class="fa-fw fas fa-archive faa-tada"></i><span> 叨逼叨</span></a></div><div class="menus_item"><a class="site-page faa-parent animated-hover" href="/tags/"><i class="fa-fw fas fa-tags faa-tada"></i><span> 标签</span></a></div><div class="menus_item"><a class="site-page faa-parent animated-hover" href="/categories/"><i class="fa-fw fas fa-folder-open faa-tada"></i><span> 分类</span></a></div><div class="menus_item"><a class="site-page faa-parent animated-hover" href="/link/"><i class="fa-fw fas fa-link faa-tada"></i><span> 友链</span></a></div><div class="menus_item"><a class="site-page faa-parent animated-hover" href="/comments/"><svg class="icon faa-tada" aria-hidden="true"><use xlink:href="#icon-message"></use></svg><span> 留言板</span></a></div><div class="menus_item"><a class="site-page faa-parent animated-hover" href="/about/"><i class="fa-fw fas fa-heart faa-tada"></i><span> 个人简介</span></a></div></div><div id="toggle-menu"><a class="site-page"><i class="fas fa-bars fa-fw"></i></a></div></div></nav><div id="post-info"><h1 class="post-title">Vue源码开发-组件的渲染10</h1><div id="post-meta"><div class="meta-firstline"><span class="post-meta-date"><i class="far fa-calendar-alt fa-fw post-meta-icon"></i><span class="post-meta-label">发表于</span><time class="post-meta-date-created" datetime="2021-01-07T16:00:00.000Z" title="发表于 2021-01-08 00:00:00">2021-01-08</time><span class="post-meta-separator">|</span><i class="fas fa-history fa-fw post-meta-icon"></i><span class="post-meta-label">更新于</span><time class="post-meta-date-updated" datetime="2021-01-07T16:00:00.000Z" title="更新于 2021-01-08 00:00:00">2021-01-08</time></span><span class="post-meta-categories"><span class="post-meta-separator">|</span><i class="fas fa-inbox fa-fw post-meta-icon"></i><a class="post-meta-categories" href="/categories/%E6%BA%90%E7%A0%81/">源码</a></span></div><div class="meta-secondline"><span class="post-meta-separator">|</span><span class="post-meta-wordcount"><i class="far fa-file-word fa-fw post-meta-icon"></i><span class="post-meta-label">字数总计:</span><span class="word-count">4.2k</span><span class="post-meta-separator">|</span><i class="far fa-clock fa-fw post-meta-icon"></i><span class="post-meta-label">阅读时长:</span><span>15分钟</span></span><span class="post-meta-separator">|</span><span class="post-meta-pv-cv" id="" data-flag-title="Vue源码开发-组件的渲染10"><i class="far fa-eye fa-fw post-meta-icon"></i><span class="post-meta-label">阅读量:</span><span id="busuanzi_value_page_pv"></span></span></div></div></div></header><main class="layout" id="content-inner"><div id="post"><article class="post-content" id="article-container"><h1 id="Vue源码开发之组件的渲染"><a href="#Vue源码开发之组件的渲染" class="headerlink" title="Vue源码开发之组件的渲染"></a>Vue源码开发之组件的渲染</h1><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="number">1.</span> 通过了解组件的合并策略 我们的组件现在已经可以使用标签的形式渲染到页面上</span><br><span class="line"><span class="number">2.</span> 这里我们回顾一下 渲染流程 首先我们会根据模版拿到对应的标签的HTML字符串</span><br><span class="line"><span class="number">3.</span> 然后根据这些字符串 去生成AST语法树 然后在根据AST语法树生成render函数 </span><br><span class="line"><span class="number">4.</span> Vue初始化的时候会去 调用这些render函数生成虚拟DOM 然后在调用_update方法创建真实DOM</span><br><span class="line"><span class="number">5.</span> 那我们的组件 定义好了之后 会以你标签的名方式写在HTML里面 然后走上面的步骤</span><br></pre></td></tr></table></figure>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">body</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">div</span> <span class="attr">id</span>=<span class="string">&quot;app&quot;</span> <span class="attr">class</span>=<span class="string">&quot;init&quot;</span> <span class="attr">style</span>=<span class="string">&quot;color: red;height: 200px;&quot;</span>&gt;</span></span><br><span class="line">         <span class="tag">&lt;<span class="name">span</span>&gt;</span>&#123;&#123;arr&#125;&#125;<span class="tag">&lt;/<span class="name">span</span>&gt;</span></span><br><span class="line">         <span class="tag">&lt;<span class="name">div</span>&gt;</span>你好<span class="tag">&lt;/<span class="name">div</span>&gt;</span></span><br><span class="line">      	 <span class="comment">&lt;!--这里是我们定义的组件--&gt;</span></span><br><span class="line">         <span class="tag">&lt;<span class="name">my-button</span>&gt;</span><span class="tag">&lt;/<span class="name">my-button</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;/<span class="name">div</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">script</span> <span class="attr">src</span>=<span class="string">&quot;./dist/umd/vue.js&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">script</span>&gt;</span></span><br><span class="line">    <span class="tag">&lt;<span class="name">script</span>&gt;</span></span><br><span class="line"><span class="javascript">        Vue.component(<span class="string">&#x27;my-button&#x27;</span>,&#123;</span></span><br><span class="line"><span class="handlebars"><span class="xml">            template:&#x27;<span class="tag">&lt;<span class="name">button</span>&gt;</span>全局按钮<span class="tag">&lt;/<span class="name">button</span>&gt;</span>&#x27;</span></span></span><br><span class="line">        &#125;)</span><br><span class="line"><span class="javascript">        <span class="keyword">let</span> vm = <span class="keyword">new</span> Vue(&#123;</span></span><br><span class="line"><span class="javascript">            el:<span class="string">&#x27;#app&#x27;</span>,</span></span><br><span class="line"><span class="javascript">            data:<span class="function"><span class="keyword">function</span>(<span class="params"></span>)</span>&#123;</span></span><br><span class="line"><span class="javascript">                <span class="keyword">return</span> &#123;</span></span><br><span class="line">                    arr:[1,2,3]</span><br><span class="line">                &#125;</span><br><span class="line">            &#125;,</span><br><span class="line">            components:&#123;</span><br><span class="line"><span class="javascript">                <span class="string">&#x27;my-button&#x27;</span>:&#123;</span></span><br><span class="line"><span class="handlebars"><span class="xml">                    template:&#x27;<span class="tag">&lt;<span class="name">button</span>&gt;</span>实例按钮<span class="tag">&lt;/<span class="name">button</span>&gt;</span>&#x27;</span></span></span><br><span class="line">                &#125;</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;)</span><br><span class="line">    <span class="tag">&lt;/<span class="name">script</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">body</span>&gt;</span></span><br></pre></td></tr></table></figure>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">&lt;!-- 初始化 之后 就变成如下的样子--&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">div</span> <span class="attr">id</span>=<span class="string">&quot;app&quot;</span> <span class="attr">class</span>=<span class="string">&quot;init&quot;</span> <span class="attr">style</span>=<span class="string">&quot;color: red; height: 200px;&quot;</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">span</span>&gt;</span>[1,2,3,456]<span class="tag">&lt;/<span class="name">span</span>&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">div</span>&gt;</span>你好<span class="tag">&lt;/<span class="name">div</span>&gt;</span></span><br><span class="line">  <span class="comment">&lt;!--此时我们的真实DOM并不是我们想要的结果 我们想要的是 组件名称里面的对应的html结构--&gt;</span></span><br><span class="line">  <span class="tag">&lt;<span class="name">my-button</span>&gt;</span><span class="tag">&lt;/<span class="name">my-button</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">div</span>&gt;</span></span><br></pre></td></tr></table></figure>
<h2 id="组件的渲染"><a href="#组件的渲染" class="headerlink" title="组件的渲染"></a>组件的渲染</h2><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="number">1.</span> 首先 在创建虚拟DOM的时候 如果你有组件 我们需要拿到组件对应的内容 也就是你的HTML字符串</span><br><span class="line"><span class="number">2.</span> 这里我们在创建虚拟DOM的时候如果是标签我们调取_c函数 然后里面会调取 createElement函数 </span><br><span class="line"><span class="number">3.</span> 所以在这个函数里面 你传进来的标签可能就是组件的标签 所以我们要做过滤</span><br><span class="line"><span class="number">4.</span> 过滤的逻辑就是 我们需要把HTML标签写成一个映射表 只有这些HTML标准标签我们采取生成虚拟DOM</span><br><span class="line"><span class="number">5.</span> 自定义组件的标签我们需要获取他对应的HTML字符串 然后在创建虚拟DOM</span><br></pre></td></tr></table></figure>
<h2 id="makeUp-方法"><a href="#makeUp-方法" class="headerlink" title="makeUp 方法"></a>makeUp 方法</h2><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="number">1.</span> 这个方法就是用来 针对HTML标准标签 去生成虚拟DOM的方法</span><br><span class="line"><span class="number">2.</span> 我们会把HTML标准标签 都写出来</span><br><span class="line"><span class="number">3.</span> 然后 做成一个高极函数 你在调用的时候 把标签传进去 返回<span class="literal">true</span> 就是 标准标签 不是自定义的标签</span><br></pre></td></tr></table></figure>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//2021 0222 1.在创建虚拟DOM的时候 我们传进来的标签可能是HTML标准标签名称</span></span><br><span class="line"><span class="comment">// 也有可能是我们的自定义组件的标签名称 所以这里要做过滤</span></span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">makeUp</span>(<span class="params">str</span>)</span>&#123;</span><br><span class="line">    <span class="keyword">const</span> map =&#123;&#125;</span><br><span class="line">    str.split(<span class="string">&#x27;,&#x27;</span>).forEach(<span class="function"><span class="params">tagName</span> =&gt;</span> &#123;</span><br><span class="line">        map[tagName] = <span class="literal">true</span></span><br><span class="line">    &#125;)</span><br><span class="line">    <span class="comment">// 是不是标准的标签 我们在调用的时候我返回一个函数 然后我们在把你的标签传进去</span></span><br><span class="line">    <span class="comment">// 这里就会返回你是不是标准标签 如果是就为true</span></span><br><span class="line">    <span class="keyword">return</span> <span class="function">(<span class="params">tag</span>) =&gt;</span> map[tag] || <span class="literal">false</span></span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="comment">//2. 判断是不是标准标签 源码中这里所有的标签都写成来了</span></span><br><span class="line"><span class="keyword">export</span>  <span class="keyword">const</span> isReservedTag = makeUp(<span class="string">&#x27;a,p,div,ul,li,span,input,button&#x27;</span>)</span><br></pre></td></tr></table></figure>
<h2 id="组件的虚拟DOM"><a href="#组件的虚拟DOM" class="headerlink" title="组件的虚拟DOM"></a>组件的虚拟DOM</h2><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="number">1.</span> 我们在创建虚拟DOM 那里 就可以根据你是HTML标准标签 还是你 自定义组件的标签去创建虚拟DOM了</span><br><span class="line"><span class="number">2.</span> 首先我们会调用我们的extend方法 把你实例的组件变成构造构造函数 这个构造函数上有我们的Vue的构造函数上的一些初始方法_init _render _update patch等等</span><br></pre></td></tr></table></figure>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">createElement</span>(<span class="params">vm,tag,data=&#123;&#125;,...children</span>)</span>&#123;</span><br><span class="line">    <span class="comment">// 这里就相当于在生成我们的虚拟DOM了 如果你是元素的化 应该生成什么样的虚拟DOM</span></span><br><span class="line">    <span class="comment">// 比如有我们的标签名 有没有数据 孩子</span></span><br><span class="line">    <span class="comment">//2021 0223 1.这里我们要判断 如果他是正常的标签 div span 之类的 我就正常生成虚拟DOM</span></span><br><span class="line">    <span class="keyword">if</span>(isReservedTag(tag))&#123;</span><br><span class="line">         <span class="keyword">return</span> vnode(vm,tag,data,data.key,children)</span><br><span class="line">    &#125;<span class="keyword">else</span>&#123;</span><br><span class="line">        <span class="comment">//2. 这里如果不是 那么就是你 自定义的组件标签 那我们就要对应的去取到他的HTML字符串</span></span><br><span class="line">        <span class="comment">// 这里我们因为之前有过合并 所以 你实例化的组件都在我们的$options.components属性上</span></span><br><span class="line">        <span class="comment">// 如果你实例话的组件找不到对应的标签名字 当时我们在做全局组件的时候做了一个原型链 会顺着原型链去找</span></span><br><span class="line">        <span class="comment">// 这里去要知道一点 我们实例的组件 是个对象 component:&#123;&#x27;my-button&#x27;:&#123;template:&#x27;&lt;div&gt;实例安努&lt;/div&gt;&#x27;&#125;&#125;  全局组件 是一个Vue的子类 </span></span><br><span class="line">        <span class="comment">// 如果是实例的组件我们就需要让他向Vue 一样做数据劫持等 初始话操作 </span></span><br><span class="line">        <span class="comment">// 这里我们就要使用Vue.extend方法去实现 可以把一个对象变成一个构造函数 这个构造函数里面有Vue构造函数上的init方法 全局组件就是调用了extend方法</span></span><br><span class="line">        <span class="comment">// 这里的Ctor 就是你实例的时候 自定义组件 &#x27;my-button&#x27; 后面对应的对象</span></span><br><span class="line">      	<span class="comment">// components:&#123;&#x27;my-button&#x27;:&#123;template:&#x27;&lt;button&gt;实例按钮&lt;/button&gt;&#x27;&#125;&#125;</span></span><br><span class="line">        <span class="keyword">const</span> Ctor = vm.$options.components[tag]</span><br><span class="line">        <span class="comment">// 调用 createComponent 方法去创建 组件的虚拟DOM</span></span><br><span class="line">        <span class="keyword">return</span> createComponent(vm,tag,data,data.key,children,Ctor)</span><br><span class="line">    &#125;</span><br><span class="line">   </span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="number">1.</span> 由于这里我们组件会有两种情况</span><br><span class="line"><span class="number">2.</span> 调用Vue.component方法创建的组件 其实是已经调用了我们的extend方法 已经把组件变成一个构造函数了</span><br><span class="line"><span class="number">3.</span> 然后就是我们实例话组件创建的 就是一个对象 此时我们也需要调用extend方法 去创建一个构造函数</span><br><span class="line"><span class="number">4.</span> extend方法 最开始我们是挂在到Vue.options._base上了  在vue初始化的时候我们已经合并到实例的$options属性上 所以直接调用即可</span><br></pre></td></tr></table></figure>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 2021 0223 2. 创建组件的虚拟Dom 方法</span></span><br><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">createComponent</span>(<span class="params">vm,tag,data,key,children,Ctor</span>)</span>&#123;</span><br><span class="line">    <span class="comment">// 如果你实例话的组件找不到对应的标签名字 当时我们在做全局组件的时候做了一个原型链 会顺着原型链去找全局注册的组件</span></span><br><span class="line">    <span class="comment">// 这里去要知道一点 我们实例的组件 是个对象 component:&#123;&#x27;my-button&#x27;:&#123;template:&#x27;&lt;div&gt;实例安努&lt;/div&gt;&#x27;&#125;&#125;  全局组件 是一个Vue的子类 是个构造函数</span></span><br><span class="line">    <span class="comment">// 如果是实例的组件我们就需要让他向Vue 一样做数据劫持等 初始话操作 </span></span><br><span class="line">    <span class="comment">// 这里我们就要使用Vue.extend方法去实现 可以把一个对象变成一个构造函数 这个构造函数里面有Vue构造函数上的init方法 全局组件就是调用了extend方法</span></span><br><span class="line">    <span class="keyword">if</span>(isObject(Ctor))&#123;</span><br><span class="line">        <span class="comment">// 这里的 就说明你是个对象 也就是实例组件  所以我们需要调取Vue.extend方法去把他转换成一个构造函数</span></span><br><span class="line">        <span class="comment">// 我们前期已经把extend方法 挂在到了Vue的对象上 然后Vue在初始化的时候我们有合并了一下 所以这个方法 在vm.$options._base身上</span></span><br><span class="line">        Ctor = vm.$options._base.extend(Ctor)</span><br><span class="line">        <span class="comment">// 这样就把我们实例上的组件 变成了构造函数 然后我们直接 new 的时候 就会走一遍 new Vue的方法 数据劫持 绑定 合并 等等</span></span><br><span class="line">        <span class="comment">// console.log(Ctor,&#x27;---ctor&#x27;)</span></span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">    <span class="comment">//2021 0223 3. 给组件增加生命周期 这里的生命周期不是 created 之类的</span></span><br><span class="line">    <span class="comment">// 这里给组件的data 添加hook的意义 是因为我们创建了虚拟DOM之后 我们要创建真实DOM</span></span><br><span class="line">  	<span class="comment">// 所以我们就要根据hook 去判断 你到底是组件的虚拟DOM去创建真实DOM 还是 HTML标准标签去创建真实DOM</span></span><br><span class="line">    data.hook = &#123;</span><br><span class="line">        <span class="comment">// 初始化钩子</span></span><br><span class="line">        <span class="comment">// 2021 0223 6. 这里知道 我们我们现在是要创建组件的虚拟 DOM</span></span><br><span class="line">        <span class="comment">// 组件的虚拟DOM创建好了之后 我们要根据 虚拟DOM 去创建真实DOM</span></span><br><span class="line">        <span class="comment">// 在创建真实DOM的时候我们需要判断 你是标准的HTML字符串 创建真实DOM 还是组件创建真实DOM</span></span><br><span class="line">        <span class="comment">// 如果判断 你是HTML字符串 还是组件 就是 在这里 如果我们是组件 就在组件的虚拟DOM的data属性上 添加了一个hook属性</span></span><br><span class="line">        <span class="comment">// 所以我们在判断你是组件的时候 再次调用了 这个init方法并且把 组件生成的vnode传入了进去 组件的vnode上 组件的构造函数</span></span><br><span class="line">        <span class="comment">// 这里我们还知道 我们实例组件 最后都会返回一个构造函数 这个构造函数继承了Vue的构造函数 上面有数据劫持 合并等一些里方法</span></span><br><span class="line">        <span class="comment">// 所以我们要调用组件的构造函数 </span></span><br><span class="line">        <span class="function"><span class="title">init</span>(<span class="params"></span>)</span>&#123;</span><br><span class="line">          </span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="comment">// 这里的Ctor.cid 就是区别不同实例创建的组件的名称不同 </span></span><br><span class="line">    <span class="comment">// 组件的虚拟节点 拥有hook 和当前组件的 componentOptions 存放的组件的构造函数</span></span><br><span class="line">    <span class="comment">// 然后我们去创建组件的虚拟节点</span></span><br><span class="line"></span><br><span class="line"></span><br><span class="line">    <span class="keyword">return</span> vnode(vm,<span class="string">`vue-component-<span class="subst">$&#123;Ctor.cid&#125;</span>-<span class="subst">$&#123;tag&#125;</span>`</span>,data,key,<span class="literal">undefined</span>,<span class="literal">undefined</span>,&#123;Ctor&#125;)</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h2 id="创建组件的真实DOM"><a href="#创建组件的真实DOM" class="headerlink" title="创建组件的真实DOM"></a>创建组件的真实DOM</h2><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="number">1.</span> 上面我们已经创建完组件的虚拟DOM了</span><br><span class="line"><span class="number">2.</span> 然后我们要创建真实DOM 那么这里就会存在一个问题 我怎么知道你是要创建组件的真实DOM 还是HTML的真实DOM</span><br><span class="line"><span class="number">3.</span> 所以我们就可以利用刚刚 组件里的data属性上的hook 去判断</span><br><span class="line"><span class="number">4.</span> 创建真实DOM 是在patch方法里 我们调用了 createElm方法 创建了真实DOM 这个方法也返回真实DOM</span><br><span class="line"><span class="number">5.</span> 然后我们在把创建好的真实DOM插入到了元素中去</span><br></pre></td></tr></table></figure>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//4. 创建我们的真实DOM</span></span><br><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">createElm</span> (<span class="params">vnode</span>)</span>&#123;</span><br><span class="line">    <span class="keyword">let</span> &#123;tag,children,key,data,text&#125; = vnode</span><br><span class="line">    <span class="comment">//4.1 如果是标签我们就创建标签 如果有儿子我们就接着创建 递归</span></span><br><span class="line">    <span class="keyword">if</span>(<span class="keyword">typeof</span> tag === <span class="string">&#x27;string&#x27;</span>)&#123;</span><br><span class="line">        <span class="comment">// 2021 0223 4. 这里我们们虚拟DOM有可能是真实标签生成的 也有个能组件生成的 </span></span><br><span class="line">        <span class="comment">// 所以这里我们要有两种 一种是根据标签生成真实节点 一种是根据组件生成真实节点</span></span><br><span class="line">        <span class="comment">// 如果是组件 我们就要拿到组件的HTML标签的字符串去创建真实节点 </span></span><br><span class="line">        <span class="keyword">if</span>(createComponent(vnode))&#123;</span><br><span class="line">            <span class="comment">// 4.1如果 createComponent 方法结果是true 那我们就要拿到 组件对应的HTML字符串</span></span><br><span class="line"></span><br><span class="line">            <span class="keyword">return</span> vnode.componentInstance.$el</span><br><span class="line">        &#125;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"></span><br><span class="line">        vnode.el = <span class="built_in">document</span>.createElement(tag)</span><br><span class="line">        <span class="comment">// 处理样式的方法 因为此时我们的样式都在我们的虚拟DOM上</span></span><br><span class="line">        updateProperties(vnode)</span><br><span class="line">        children.forEach(<span class="function"><span class="params">child</span> =&gt;</span> &#123;</span><br><span class="line">            <span class="comment">//并且 插入到我们创建好的元素中</span></span><br><span class="line">            vnode.el.appendChild(createElm(child))</span><br><span class="line">        &#125;)</span><br><span class="line">    &#125;<span class="keyword">else</span>&#123;</span><br><span class="line">        <span class="comment">//4.2 如果是文本我们就直接创建</span></span><br><span class="line">        vnode.el = <span class="built_in">document</span>.createTextNode(text)</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="comment">//最后创建好的 就是返回的我们的真实元素 </span></span><br><span class="line">    <span class="keyword">return</span> vnode.el</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h2 id="createComponent方法"><a href="#createComponent方法" class="headerlink" title="createComponent方法"></a>createComponent方法</h2><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="number">1.</span> 这个方法就是判断 你是不是组件来创建真实DOM</span><br><span class="line"><span class="number">2.</span> 并且我们刚刚调用vnode方法创建虚拟DOM的时候 把我们extend出来的构造函数也传进去了 也就是说我们创建出来的虚拟DOM里 能拿到 我创建出来的构造函数</span><br><span class="line"><span class="number">3.</span> 既然我们能拿到组件的构造函数了 我们就可以<span class="keyword">new</span>然后来初始化这个组件了</span><br><span class="line"><span class="number">4.</span> 以上就是这个方法的作用</span><br></pre></td></tr></table></figure>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 2023 0223 5.createComponent方法用来判断是不是组件</span></span><br><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">createComponent</span>(<span class="params">vnode</span>)</span>&#123;</span><br><span class="line">    <span class="comment">// 这里我们知道 你是不是组件的  是因为我们刚刚 创建vnode 的时候 如果是组件的虚拟DOM 我们在data上加了一个hook属性</span></span><br><span class="line">    <span class="comment">// 所以我们可以根据hook属性去判断 你是不是组件</span></span><br><span class="line">    <span class="keyword">let</span> i = vnode.data</span><br><span class="line">    <span class="comment">// 这里的逻辑我先去看看 i上面有没有hook  如果有我 把hook 赋值给 i 走下一个 然后在看看 有没有init 方法 如果有我就赋值给i</span></span><br><span class="line">    <span class="keyword">if</span>((i = i.hook) &amp;&amp; (i = i.init))&#123;</span><br><span class="line">        <span class="comment">// 这里我们就相当于调取了 data.hook.init方法 这里 hook 属性是有只有组件才有的</span></span><br><span class="line">        i(vnode)</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">if</span>(vnode.componentInstance)&#123;</span><br><span class="line">        <span class="keyword">return</span> <span class="literal">true</span></span><br><span class="line">    &#125;</span><br><span class="line">    <span class="comment">// 如果取 不到 我们就返回false</span></span><br><span class="line">    <span class="keyword">return</span> <span class="literal">false</span></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 以上操作完毕之后 我们就知道 你已经是组件来创建真实的DOM了 所以这里我们可以在data.hooke里的init方法中去new一下 这样 他上面就会有我们Vue上所有的方法_init 啊 数据劫持啊 等等 </span></span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">createElement</span>(<span class="params">vm,tag,data=&#123;&#125;,...children</span>)</span>&#123;</span><br><span class="line">    <span class="keyword">if</span>(isReservedTag(tag))&#123;</span><br><span class="line">         <span class="keyword">return</span> vnode(vm,tag,data,data.key,children)</span><br><span class="line">    &#125;<span class="keyword">else</span>&#123;</span><br><span class="line">        <span class="keyword">const</span> Ctor = vm.$options.components[tag]</span><br><span class="line">        <span class="keyword">return</span> createComponent(vm,tag,data,data.key,children,Ctor)</span><br><span class="line">    &#125;</span><br><span class="line">   </span><br><span class="line">&#125;</span><br><span class="line"><span class="function"><span class="keyword">function</span> <span class="title">createComponent</span>(<span class="params">vm,tag,data,key,children,Ctor</span>)</span>&#123;</span><br><span class="line">    <span class="keyword">if</span>(isObject(Ctor))&#123;</span><br><span class="line">        Ctor = vm.$options._base.extend(Ctor)</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    data.hook = &#123;</span><br><span class="line">        <span class="function"><span class="title">init</span>(<span class="params">vnode</span>)</span>&#123;</span><br><span class="line">          	<span class="comment">// 经过以上的操作代码就会走到这里来</span></span><br><span class="line">            <span class="comment">// 然后我们就开始new一下这个组件的构造函数 这里因为我们的调用extend的时候已经把配置项传进去了  所以不用子传 new 完之后 他vue 初始化的流程一样 </span></span><br><span class="line">            <span class="keyword">let</span> child = vnode.componentInstance =  <span class="keyword">new</span> vnode.componentOptions.Ctor(&#123;&#125;)</span><br><span class="line">            <span class="comment">// 由于这里我们有传el 所以不会挂载 然后我们调用 $mount方法 有会走 ast语法树解析  数据劫持 关联dep watcher 等等  生成render函数 创建虚拟DOM 这个时候创建的虚拟DOM就是你组件template里面的对应的HTML字符串了 </span></span><br><span class="line">            <span class="comment">// 然后开始挂在的逻辑 生成虚拟DOM 走到patch 方法 开始走里的挂载逻辑等等</span></span><br><span class="line">            child.$mount()</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="keyword">return</span> vnode(vm,<span class="string">`vue-component-<span class="subst">$&#123;Ctor.cid&#125;</span>-<span class="subst">$&#123;tag&#125;</span>`</span>,data,key,<span class="literal">undefined</span>,<span class="literal">undefined</span>,&#123;Ctor&#125;)</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 由于我们创建完组件的虚拟DOM之后没有 传el属性 所以我们需要在创建真实DOM的时候去判断一下 也就patch的方法中最开始</span></span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="keyword">export</span> <span class="function"><span class="keyword">function</span> <span class="title">patch</span>(<span class="params">oldVnode,vnode</span>) </span>&#123;</span><br><span class="line"></span><br><span class="line">		<span class="comment">// 如果我们是首次挂载 这个 oldVnode 就是我们的&lt;div id=&quot;app&quot;&gt;&lt;/div&gt; 所以会有值</span></span><br><span class="line">  	<span class="comment">// 如果是我们的组件挂载 那么我们是没传el的 所以要判断一下</span></span><br><span class="line">    <span class="comment">// 这里 组件会直接去查找我们的父亲节点 直接挂载到上面</span></span><br><span class="line">    <span class="keyword">if</span>(!oldVnode)&#123;</span><br><span class="line">        <span class="keyword">return</span> createElm(vnode)</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">const</span> isRealElement = oldVnode.nodeType</span><br><span class="line">    <span class="keyword">if</span>(isRealElement)&#123;</span><br><span class="line">        <span class="comment">//1. 这里面就是如果是首次渲染 就把我们的vnode虚拟DOM生成我们的真实DOM</span></span><br><span class="line">        <span class="comment">// 该创建元素的创建元素 该生成文本的 生成文本</span></span><br><span class="line">        <span class="comment">// 然后我们最早挂在el上的元素干掉替换成我们的创建好的真实DOM</span></span><br><span class="line">        <span class="comment">//2. 根据虚拟DOM创建真实DOM</span></span><br><span class="line">        <span class="keyword">let</span> el = createElm(vnode)</span><br><span class="line">        <span class="comment">//3. 第一次 oldVnode 就是我们的&lt;div id=&quot;app&quot;&gt;&lt;/div&gt;</span></span><br><span class="line">        <span class="comment">// 然后拿到我们的父节点删除我们的老节点</span></span><br><span class="line">        <span class="keyword">let</span> parentElm = oldVnode.parentNode</span><br><span class="line">        <span class="comment">// 然后把我们创建好的真实DOM 插入进去我们老节点的下一个节点</span></span><br><span class="line">        parentElm.insertBefore(el,oldVnode.nextSibling)</span><br><span class="line">        <span class="comment">//然后移除我们的元素</span></span><br><span class="line">        parentElm.removeChild(oldVnode)</span><br><span class="line">        <span class="keyword">return</span> el</span><br><span class="line">    &#125; <span class="keyword">else</span> &#123;</span><br><span class="line"></span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<h2 id="总结"><a href="#总结" class="headerlink" title="总结"></a>总结</h2><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="number">1.</span> 首先我们要知道 我们创建组件的方式 有全局组件 调用 Vue.component方法 这种方式创建出来的 是一个构造函数</span><br><span class="line"><span class="number">2.</span> 还有就是在实例的components属性上创建出来的 这种方式最后也调用extend方法转变成 构造函数</span><br><span class="line"><span class="number">3.</span> 为什么要转换成构造函数 是因为 我们转换的构造函数 继承了我们Vue构造函数 我们组件里的配置项 data methods 渲染到页面 数据劫持 也不更新等 等等属性也需要 初始化</span><br><span class="line"><span class="number">4.</span> 这件事情我们是在创建虚拟DOM的时候 去做的 也就是 我们现在创建虚拟DOM的时候 有两种情况 第一种就是你标准的HTML标签 去创建的虚拟DOM 第二种就是你的组件组件创建虚拟DOM  这里要清楚一点 此时我们只是为了分清楚 你到底是 HTML标签去创建虚拟DOM 还是 标准的HTML去创建</span><br><span class="line"><span class="number">5.</span> 组件去创建虚拟DOM 此时我们已经把创建好的组件的构造函数 挂载到了组件的虚拟DOM上 而在创建真实的DOM的时候我们 <span class="keyword">new</span> 这个构造函数 那么他又会在走一次我们 <span class="keyword">new</span> Vue 的时候流程</span><br><span class="line"><span class="number">6.</span> 在这个时候我们才是真正的去创建了组件的虚拟DOM 上一次只为了区分 你是HTML来创建虚拟DOM 还是组件来创建虚拟DOM</span><br></pre></td></tr></table></figure>
</article><div class="post-copyright"><div class="post-copyright__title"><span class="post-copyright-info"><h>Vue源码开发-组件的渲染10</h></span></div><div class="post-copyright__type"><span class="post-copyright-info"><a href="http://example.com/2021/01/08/Vue%E6%BA%90%E7%A0%81%E5%BC%80%E5%8F%91%E4%B9%8B%E7%BB%84%E4%BB%B6%E7%9A%84%E6%B8%B2%E6%9F%9310/">http://example.com/2021/01/08/Vue%E6%BA%90%E7%A0%81%E5%BC%80%E5%8F%91%E4%B9%8B%E7%BB%84%E4%BB%B6%E7%9A%84%E6%B8%B2%E6%9F%9310/</a></span></div><div class="post-copyright-m"><div class="post-copyright-m-info"><div class="post-copyright-a"><h>作者</h><div class="post-copyright-cc-info"><h>北城韩雨</h></div></div><div class="post-copyright-c"><h>发布于</h><div class="post-copyright-cc-info"><h>2021-01-08</h></div></div><div class="post-copyright-u"><h>更新于</h><div class="post-copyright-cc-info"><h>2021-01-08</h></div></div><div class="post-copyright-c"><h>许可协议</h><div class="post-copyright-cc-info"><a class="icon" rel="noopener" target="_blank" title="Creative Commons" href="https://creativecommons.org/"><i class="fab fa-creative-commons"></i></a><a rel="noopener" target="_blank" title="CC BY-NC-SA 4.0" href="https://creativecommons.org/licenses/by-nc-sa/4.0/">CC BY-NC-SA 4.0</a></div></div></div></div></div><div class="tag_share"><div class="post-meta__tag-list"><a class="post-meta__tags" href="/tags/Vue/">Vue</a></div><div class="post_share"></div></div><link rel="stylesheet" href="/" media="defer" onload="this.media='all'"/><div class="post-reward"><button class="tip-button reward-button"><span class="tip-button__text">打赏</span><div class="coin-wrapper"><div class="coin"><div class="coin__middle"></div><div class="coin__back"></div><div class="coin__front"></div></div></div><div class="reward-main"><ul class="reward-all"><li class="reward-item"><a href="/img/weixin.jpg" target="_blank"><img class="post-qr-code-img" src="/img/weixin.jpg" alt="微信"/></a><div class="post-qr-code-desc">微信</div></li><li class="reward-item"><a href="/img/taobao.jpg" target="_blank"><img class="post-qr-code-img" src="/img/taobao.jpg" alt="支付宝"/></a><div class="post-qr-code-desc">支付宝</div></li></ul></div></button></div><script defer="defer" src="/"></script><nav class="pagination-post" id="pagination"><div class="prev-post pull-left"><a href="/2021/04/16/gin-vue-admin/"><img class="prev-cover" src="/img/gin-vue-admin.jpg" onerror="onerror=null;src='/img/404.jpg'" alt="cover of previous post"><div class="pagination-info"><div class="label">上一篇</div><div class="prev_info">Gin-Vue-Admin</div></div></a></div><div class="next-post pull-right"><a href="/2021/01/07/Vue%E6%BA%90%E7%A0%81%E5%BC%80%E5%8F%91%E4%B9%8B%E7%BB%84%E4%BB%B6%E7%9A%84%E5%90%88%E5%B9%B6%E7%AD%96%E7%95%A509/"><img class="next-cover" src="https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fcz-video-photo.oss-cn-beijing.aliyuncs.com%2F20191017%2F4cfc341591d242327b67e9ceb6953612_00002.jpg&amp;refer=http%3A%2F%2Fcz-video-photo.oss-cn-beijing.aliyuncs.com&amp;app=2002&amp;size=f9999,10000&amp;q=a80&amp;n=0&amp;g=0n&amp;fmt=jpeg?sec=1629530702&amp;t=80943e12d5239f63beafd6d1c540855f" onerror="onerror=null;src='/img/404.jpg'" alt="cover of next post"><div class="pagination-info"><div class="label">下一篇</div><div class="next_info">Vue源码开发-组件合并策略09</div></div></a></div></nav><div class="relatedPosts"><div class="headline"><i class="fas fa-thumbs-up fa-fw"></i><span> 相关推荐</span></div><div class="relatedPosts-list"><div><a href="/2021/04/16/gin-vue-admin/" title="Gin-Vue-Admin"><img class="cover" src="/img/gin-vue-admin.jpg" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2021-04-16</div><div class="title">Gin-Vue-Admin</div></div></a></div><div><a href="/2021/01/07/Vue源码开发之组件的合并策略09/" title="Vue源码开发-组件合并策略09"><img class="cover" src="https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fcz-video-photo.oss-cn-beijing.aliyuncs.com%2F20191017%2F4cfc341591d242327b67e9ceb6953612_00002.jpg&refer=http%3A%2F%2Fcz-video-photo.oss-cn-beijing.aliyuncs.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1629530702&t=80943e12d5239f63beafd6d1c540855f" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2021-01-07</div><div class="title">Vue源码开发-组件合并策略09</div></div></a></div><div><a href="/2021/01/06/Vue源码开发之数组的依赖收集08/" title="Vue源码开发-数组的依赖收集08"><img class="cover" src="https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fpic.vjshi.com%2F2018-07-17%2F3eca5394963b50e37b7be2ba320029ec%2F00003.jpg%3Fx-oss-process%3Dstyle%2Fwatermark&refer=http%3A%2F%2Fpic.vjshi.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1629530644&t=10679b5732c52e39eeb588040240a790" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2021-01-06</div><div class="title">Vue源码开发-数组的依赖收集08</div></div></a></div><div><a href="/2021/01/06/Vue源码开发之生命周期合并07/" title="Vue源码开发-生命周期合并07"><img class="cover" src="https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fpic.vjshi.com%2F2018-07-17%2Faf41dabad727ba80c9ca8a2bfbd22a58%2F00004.jpg%3Fx-oss-process%3Dstyle%2Fwatermark&refer=http%3A%2F%2Fpic.vjshi.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1629530659&t=bbcfe1e86f393eecbb0722db1b92e475" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2021-01-06</div><div class="title">Vue源码开发-生命周期合并07</div></div></a></div><div><a href="/2021/01/05/Vue源码开发之批量更新06/" title="Vue源码开发-批量更新06"><img class="cover" src="https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fpic.vjshi.com%2F2018-07-17%2F3eca5394963b50e37b7be2ba320029ec%2F00003.jpg%3Fx-oss-process%3Dstyle%2Fwatermark&refer=http%3A%2F%2Fpic.vjshi.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1629530644&t=10679b5732c52e39eeb588040240a790" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2021-01-05</div><div class="title">Vue源码开发-批量更新06</div></div></a></div><div><a href="/2021/01/04/Vue源码开发之对象依赖收集05/" title="Vue源码开发-数据收集依赖05"><img class="cover" src="https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fpic.vjshi.com%2F2016-12-29%2F0604092c7129acd0f4029c6728db7fd7%2F00001.jpg%3Fx-oss-process%3Dstyle%2Fwatermark&refer=http%3A%2F%2Fpic.vjshi.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1629530724&t=333c5056a813a542419e5b661ebcfcd9" alt="cover"><div class="content is-center"><div class="date"><i class="far fa-calendar-alt fa-fw"></i> 2021-01-04</div><div class="title">Vue源码开发-数据收集依赖05</div></div></a></div></div></div></div><div class="aside-content" id="aside-content"><div class="card-widget card-info"><div class="is-center"><div class="avatar-img"><img src="/img/my.jpg" onerror="this.onerror=null;this.src='/img/friend_404.gif'" alt="avatar"/></div><div class="author-info__name">北城韩雨</div><div class="author-info__description">一个前端界的小学生</div></div><div class="card-info-data"><div class="card-info-data-item is-center"><a href="/archives/"><div class="headline">文章</div><div class="length-num">65</div></a></div><div class="card-info-data-item is-center"><a href="/tags/"><div class="headline">标签</div><div class="length-num">23</div></a></div><div class="card-info-data-item is-center"><a href="/categories/"><div class="headline">分类</div><div class="length-num">21</div></a></div></div><a class="button--animated" id="card-info-btn" target="_blank" rel="noopener" href="https://github.com/wazer1987"><i class="fab fa-github"></i><span>Follow Me</span></a><div class="card-info-social-icons is-center"><a class="social-icon" href="/wangzhengvslike@163.com" target="_blank" title="Email"><i class="fas fa-envelope"></i></a></div></div><div class="card-widget card-announcement"><div class="item-headline"><i class="fas fa-bullhorn card-announcement-animation"></i><span>公告</span></div><div class="announcement_content"><p>感谢访问本站，如喜欢请收藏。本站主要分享前端知识，立志成为资深前端工程师，但目前是一个前端界的小学生 若喜欢可以打赏请博主喝一杯冰阔落</p> <p>另外请大家多多支持淼哥的开源项目</p> <p>https://github.com/flipped-aurora/gin-vue-admin</p> <p>🌟🌟欢迎大家start 🌟🌟</p> <p>欢迎加入博主的前端技术交流群</p> <p style="background:rgba(255,255,255,1);margin:0"> <img src="/img/code.png"></img> </p></div></div><div class="sticky_layout"><div class="card-widget" id="card-toc"><div class="item-headline"><i class="fas fa-stream"></i><span>目录</span></div><div class="toc-content"><ol class="toc"><li class="toc-item toc-level-1"><a class="toc-link" href="#Vue%E6%BA%90%E7%A0%81%E5%BC%80%E5%8F%91%E4%B9%8B%E7%BB%84%E4%BB%B6%E7%9A%84%E6%B8%B2%E6%9F%93"><span class="toc-text">Vue源码开发之组件的渲染</span></a><ol class="toc-child"><li class="toc-item toc-level-2"><a class="toc-link" href="#%E7%BB%84%E4%BB%B6%E7%9A%84%E6%B8%B2%E6%9F%93"><span class="toc-text">组件的渲染</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#makeUp-%E6%96%B9%E6%B3%95"><span class="toc-text">makeUp 方法</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E7%BB%84%E4%BB%B6%E7%9A%84%E8%99%9A%E6%8B%9FDOM"><span class="toc-text">组件的虚拟DOM</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%88%9B%E5%BB%BA%E7%BB%84%E4%BB%B6%E7%9A%84%E7%9C%9F%E5%AE%9EDOM"><span class="toc-text">创建组件的真实DOM</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#createComponent%E6%96%B9%E6%B3%95"><span class="toc-text">createComponent方法</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E6%80%BB%E7%BB%93"><span class="toc-text">总结</span></a></li></ol></li></ol></div></div><div class="card-widget card-recent-post"><div class="item-headline"><i class="fas fa-history"></i><span>最新文章</span></div><div class="aside-list"><div class="aside-list-item"><a class="thumbnail" href="/2021/04/16/gin-vue-admin/" title="Gin-Vue-Admin"><img src="/img/gin-vue-admin.jpg" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="Gin-Vue-Admin"/></a><div class="content"><a class="title" href="/2021/04/16/gin-vue-admin/" title="Gin-Vue-Admin">Gin-Vue-Admin</a><time datetime="2021-04-15T16:00:00.000Z" title="发表于 2021-04-16 00:00:00">2021-04-16</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/2021/01/08/Vue%E6%BA%90%E7%A0%81%E5%BC%80%E5%8F%91%E4%B9%8B%E7%BB%84%E4%BB%B6%E7%9A%84%E6%B8%B2%E6%9F%9310/" title="Vue源码开发-组件的渲染10"><img src="https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fpic.vjshi.com%2F2018-07-17%2F3eca5394963b50e37b7be2ba320029ec%2F00003.jpg%3Fx-oss-process%3Dstyle%2Fwatermark&amp;refer=http%3A%2F%2Fpic.vjshi.com&amp;app=2002&amp;size=f9999,10000&amp;q=a80&amp;n=0&amp;g=0n&amp;fmt=jpeg?sec=1629530644&amp;t=10679b5732c52e39eeb588040240a790" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="Vue源码开发-组件的渲染10"/></a><div class="content"><a class="title" href="/2021/01/08/Vue%E6%BA%90%E7%A0%81%E5%BC%80%E5%8F%91%E4%B9%8B%E7%BB%84%E4%BB%B6%E7%9A%84%E6%B8%B2%E6%9F%9310/" title="Vue源码开发-组件的渲染10">Vue源码开发-组件的渲染10</a><time datetime="2021-01-07T16:00:00.000Z" title="发表于 2021-01-08 00:00:00">2021-01-08</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/2021/01/07/Vue%E6%BA%90%E7%A0%81%E5%BC%80%E5%8F%91%E4%B9%8B%E7%BB%84%E4%BB%B6%E7%9A%84%E5%90%88%E5%B9%B6%E7%AD%96%E7%95%A509/" title="Vue源码开发-组件合并策略09"><img src="https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fcz-video-photo.oss-cn-beijing.aliyuncs.com%2F20191017%2F4cfc341591d242327b67e9ceb6953612_00002.jpg&amp;refer=http%3A%2F%2Fcz-video-photo.oss-cn-beijing.aliyuncs.com&amp;app=2002&amp;size=f9999,10000&amp;q=a80&amp;n=0&amp;g=0n&amp;fmt=jpeg?sec=1629530702&amp;t=80943e12d5239f63beafd6d1c540855f" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="Vue源码开发-组件合并策略09"/></a><div class="content"><a class="title" href="/2021/01/07/Vue%E6%BA%90%E7%A0%81%E5%BC%80%E5%8F%91%E4%B9%8B%E7%BB%84%E4%BB%B6%E7%9A%84%E5%90%88%E5%B9%B6%E7%AD%96%E7%95%A509/" title="Vue源码开发-组件合并策略09">Vue源码开发-组件合并策略09</a><time datetime="2021-01-06T16:00:00.000Z" title="发表于 2021-01-07 00:00:00">2021-01-07</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/2021/01/06/Vue%E6%BA%90%E7%A0%81%E5%BC%80%E5%8F%91%E4%B9%8B%E6%95%B0%E7%BB%84%E7%9A%84%E4%BE%9D%E8%B5%96%E6%94%B6%E9%9B%8608/" title="Vue源码开发-数组的依赖收集08"><img src="https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fpic.vjshi.com%2F2018-07-17%2F3eca5394963b50e37b7be2ba320029ec%2F00003.jpg%3Fx-oss-process%3Dstyle%2Fwatermark&amp;refer=http%3A%2F%2Fpic.vjshi.com&amp;app=2002&amp;size=f9999,10000&amp;q=a80&amp;n=0&amp;g=0n&amp;fmt=jpeg?sec=1629530644&amp;t=10679b5732c52e39eeb588040240a790" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="Vue源码开发-数组的依赖收集08"/></a><div class="content"><a class="title" href="/2021/01/06/Vue%E6%BA%90%E7%A0%81%E5%BC%80%E5%8F%91%E4%B9%8B%E6%95%B0%E7%BB%84%E7%9A%84%E4%BE%9D%E8%B5%96%E6%94%B6%E9%9B%8608/" title="Vue源码开发-数组的依赖收集08">Vue源码开发-数组的依赖收集08</a><time datetime="2021-01-05T16:00:00.000Z" title="发表于 2021-01-06 00:00:00">2021-01-06</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/2021/01/06/Vue%E6%BA%90%E7%A0%81%E5%BC%80%E5%8F%91%E4%B9%8B%E7%94%9F%E5%91%BD%E5%91%A8%E6%9C%9F%E5%90%88%E5%B9%B607/" title="Vue源码开发-生命周期合并07"><img src="https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fpic.vjshi.com%2F2018-07-17%2Faf41dabad727ba80c9ca8a2bfbd22a58%2F00004.jpg%3Fx-oss-process%3Dstyle%2Fwatermark&amp;refer=http%3A%2F%2Fpic.vjshi.com&amp;app=2002&amp;size=f9999,10000&amp;q=a80&amp;n=0&amp;g=0n&amp;fmt=jpeg?sec=1629530659&amp;t=bbcfe1e86f393eecbb0722db1b92e475" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="Vue源码开发-生命周期合并07"/></a><div class="content"><a class="title" href="/2021/01/06/Vue%E6%BA%90%E7%A0%81%E5%BC%80%E5%8F%91%E4%B9%8B%E7%94%9F%E5%91%BD%E5%91%A8%E6%9C%9F%E5%90%88%E5%B9%B607/" title="Vue源码开发-生命周期合并07">Vue源码开发-生命周期合并07</a><time datetime="2021-01-05T16:00:00.000Z" title="发表于 2021-01-06 00:00:00">2021-01-06</time></div></div></div></div></div></div></main><footer id="footer"><div id="footer-wrap"><div class="copyright"><span>&copy;2017 - 2021</span><svg style="width:2em; height:2em;position: relative;top: 10px;" aria-hidden="true"><use xlink:href="#icon-Butterfly"></use></svg><span>北城韩雨</span></div><div class="framework-info"><span>框架 </span><a target="_blank" rel="noopener" href="https://hexo.io">Hexo</a><span class="footer-separator">|</span><span>主题 </span><a target="_blank" rel="noopener" href="https://github.com/jerryc127/hexo-theme-butterfly">Butterfly</a></div><div class="footer_custom_text"><p><a style="margin-inline:5px" target="_blank" href="https://hexo.io/"><img src="https://img.shields.io/badge/Frame-Hexo-blue?style=flat&logo=hexo" title="博客框架为Hexo"></a><a style="margin-inline:5px" target="_blank" href="https://butterfly.js.org/"><img src="https://img.shields.io/badge/Theme-Butterfly-6513df?style=flat&logo=bitdefender" title="主题采用butterfly"></a><a style="margin-inline:5px" target="_blank" href="https://www.jsdelivr.com/"><img src="https://img.shields.io/badge/CDN-jsDelivr-orange?style=flat&logo=jsDelivr" title="本站使用JsDelivr为静态资源提供CDN加速"></a></p></div></div></footer></div><div id="rightside"><div id="rightside-config-hide"><button id="readmode" type="button" title="阅读模式"><i class="fas fa-book-open"></i></button><button id="darkmode" type="button" title="浅色和深色模式转换"><i class="fas fa-adjust"></i></button></div><div id="rightside-config-show"><button id="rightside_config" type="button" title="设置"><i class="fas fa-cog fa-spin"></i></button><button class="close" id="mobile-toc-button" type="button" title="目录"><i class="fas fa-list-ul"></i></button><button id="go-up" type="button" title="回到顶部"><i class="fas fa-arrow-up"></i></button></div></div><div><script src="/js/utils.js"></script><script src="/js/main.js"></script><script src="https://cdn.jsdelivr.net/npm/medium-zoom/dist/medium-zoom.min.js"></script><div class="js-pjax"></div><script defer src="/live2d-widget/autoload.js"></script><script src="/js/coin.js"></script><script async src="//at.alicdn.com/t/font_2700632_3rtvhzzpl3h.js"></script><script src="/js/liuxing.js" data-pjax></script><canvas class="fireworks" mobile="false"></canvas><script src="https://cdn.jsdelivr.net/npm/butterfly-extsrc@1/dist/fireworks.min.js"></script><script src="https://cdn.jsdelivr.net/npm/butterfly-extsrc@1/dist/activate-power-mode.min.js"></script><script>POWERMODE.colorful = true;
POWERMODE.shake = true;
POWERMODE.mobile = false;
document.body.addEventListener('input', POWERMODE);
</script><script async data-pjax src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script></div><!-- hexo injector body_end start --><div class="js-pjax"><script async="async">var arr = document.getElementsByClassName('recent-post-item');
for(var i = 0;i<arr.length;i++){
    arr[i].classList.add('wow');
    arr[i].classList.add('animate__zoomIn');
    arr[i].setAttribute('data-wow-duration', '1s');
    arr[i].setAttribute('data-wow-delay', '0ms');
    arr[i].setAttribute('data-wow-offset', '100');
    arr[i].setAttribute('data-wow-iteration', '1');
  }</script><script async="async">var arr = document.getElementsByClassName('card-widget');
for(var i = 0;i<arr.length;i++){
    arr[i].classList.add('wow');
    arr[i].classList.add('animate__zoomIn');
    arr[i].setAttribute('data-wow-duration', '');
    arr[i].setAttribute('data-wow-delay', '');
    arr[i].setAttribute('data-wow-offset', '');
    arr[i].setAttribute('data-wow-iteration', '');
  }</script></div><script defer src="https://cdn.jsdelivr.net/gh/graingert/wow@1.3.0/dist/wow.min.js"></script><script defer src="https://cdn.jsdelivr.net/npm/hexo-butterfly-wowjs/lib/wow_init.min.js"></script><script async src="//at.alicdn.com/t/font_2032782_8d5kxvn09md.js"></script><!-- hexo injector body_end end --></body></html>